const gulp = require("gulp");
const uglify = require("gulp-uglify");
const webserver = require("gulp-webserver");
const sass  = require("gulp-sass");
const json = require("gulp-json");



gulp.task("server", ["static"], ()=>{
	gulp.src("dist")
		.pipe( webserver({
			port : 8000,
			//open : true,
			livereload : true,
			proxies : [
				{
					source: "ccc",
					target: ""
				} 
			]
		}) )
	gulp.watch("src/pages/**/*.js", ["compileJS"]);
	gulp.watch("src/scripts/**/*.js", ["compileJS"]);
	gulp.watch("src/conf/**/*.js", ["compileJS"]);
	gulp.watch("src/pages/**/*.html", ["compileHTML"])
	gulp.watch("src/styles/**/*.scss", ["compileCSS"])
	
	
})

gulp.task("compileCSS", ()=>{
	gulp.src("src/styles/**/*.scss")
		.pipe( sass().on('error', sass.logError) )
		.pipe( gulp.dest("dist/styles/") )
})

gulp.task("compileJSON",()=>{
	gulp.src("src/pages/**/*.json")
		.pipe(gulp.dest("dist/pages/"))
})
gulp.task("compileHTML", ()=>{
	gulp.src("src/pages/**/*.html")
		.pipe( gulp.dest("dist/pages/") )
}) 
gulp.task("compileJS", ()=>{
	gulp.src("src/pages/**/*.js")
		 //.pipe( uglify() )
		.pipe( gulp.dest("dist/pages/") )
	gulp.src("src/scripts/**/*.js")
		 //.pipe( uglify() )
		.pipe( gulp.dest("dist/scripts/") )
	gulp.src("src/conf/**/*.js")
		// .pipe( uglify() )
		.pipe( gulp.dest("dist/conf/") )
})

gulp.task("static", ()=>{
	gulp.src("src/static/**/*.*")
		.pipe( gulp.dest("dist/static/") )
	gulp.src("src/pages/**/*.json")
		.pipe( gulp.dest("dist/pages/") )
})